package cn.kgc.vue.controller;

import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.commons.ResponseResult;
import cn.kgc.vue.entity.Schedule;
import cn.kgc.vue.service.ScheduleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 课工场
 * @date 2024/4/19
 * @description 开班计划控制层
 */

@RestController
@RequestMapping("schedule")
@Api(tags = "开班计划")
public class ScheduleController {


    @Resource
    private ScheduleService scheduleService;
    // 开班计划分页数据
    @PostMapping("page")
    @ApiOperation("开班计划分页数据")
    public ResponseResult schedulePage(@RequestBody QueryCondition<Schedule> queryCondition) {
        return  scheduleService.schedulePage(queryCondition);
    }


    @PostMapping("addOrUpdate")
    @ApiOperation("添加修改开班计划")
    public ResponseResult addOrUpdateSchedule(@RequestBody Schedule schedule) {

        scheduleService.saveOrUpdate(schedule);
        return  ResponseResult.success();
    }


    @GetMapping("getById/{id}")
    @ApiOperation("根据id获取开班计划")
    public ResponseResult getScheduleById(@PathVariable("id") Integer id) {

        Schedule schedule = scheduleService.getById(id);

        return  ResponseResult.success()
                .data("schedule",schedule);
    }


    @DeleteMapping("delete/{id}")
    @ApiOperation("根据id获取开班计划")
    public ResponseResult deleteScheduleById(@PathVariable("id") Integer id) {

        scheduleService.removeById(id);

        return  ResponseResult.success()
                .message("删除成功");
    }


}
